#!/bin/bash
ecocycData="./ecoli/ecocyc/"
working_directory="./example"

libs_dir="./libs"
java_cp="$libs_dir/jgrapht-jdk1.6.jar:$libs_dir/colt-1.2.0.jar"

k="5"
threads="2"
input="${working_directory}/modele.txt"
queries="${working_directory}/queries_10_genes.txt"
#queries="${working_directory}/philippes-couples+.txt"
queries_bioasp="${working_directory}/queries_10_genes_asp.txt"
#queries_bioasp="${working_directory}/philippes-couples.txt"
genome_biosp="${working_directory}/genome.txt"
metabolism_bioasp="${working_directory}/metabolism.txt"
catalyze="${working_directory}/catalyze.txt"
association_bioasp="${working_directory}/catalyze_inv.txt"
assoReact="${working_directory}/associationsR.txt"
output="${working_directory}/result_${k}sips.txt"
output_filtered="${working_directory}/result_${k}sips_filtered.txt"
output_bioasp="${working_directory}/result_${k}sips_bioasp.txt"
labels="${working_directory}/labels.txt" 
result="${working_directory}/result_${k}sips_trad.txt" 


#java_cp="$libs_dir/jgrapht-jdk1.6.jar:$libs_dir/colt-1.2.0.jar:$libs_dir/collections-generic-4.01.jar"
#-------------------------------------------#
#        "Reaction list generation"         #
#-------------------------------------------#

#permut columns
awk '{print $2 "\t" $1}' "$catalyze" > "$association_bioasp"

echo "k-SIPs Computation - dedicated"
#Creating a list of kSIPs queries as a list of couple of start -> end reaction with some filtering options.
#java -classpath sipper.jar:"$java_cp" combi.wip.sipper.exec.GenerateKSIPsEndPoints l|i fileIn fileOut none|geneDistance=XX|reactionDistance=XX
# - The first parameter is "l" or "i" and defines the form of the entry file. The parameter "l" means the entry file is a set of reaction and all possible couples from this set will be generate. The parameter "i" indicate that the list is already under the form r1 -> r2 and no more couples will be generate.
# - none means no filtering, geneDistance=XX keep only reactions that are distant at most XX genes (i.e. in an interval of x+1 genes), end reactionDistance=XX  keep only reaction that are distant at most XX arcs in the graph reaction.
time java -Xss1024m -Xms512m -Xmx2048m -classpath sipper.jar:"$java_cp" combi.wip.sipper.exec.ComputeKSIPs "$input" "$queries" "$assoReact" "$k" "$output" "$threads"


echo "Filtering k-SIPs"
time java -classpath sipper.jar combi.wip.sipper.exec.ExtractSimple "$output" "$output_filtered" "w=300"

echo "Translating k-SIPs"
time java -classpath sipper.jar combi.wip.sipper.exec.TransSimple "$output" "$labels" "$result"

echo "k-SIPs Computation - bioASP"
time python2.7 finder_ksip.py "$genome_biosp" "$metabolism_bioasp" "$association_bioasp" "$k" "$queries_bioasp" > "$output_bioasp"
